package com.zx.dsptuneup_cloud.Tools;

import android.app.Service;
import android.content.Intent;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Binder;
import android.os.IBinder;

import androidx.annotation.Nullable;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.TimeZone;

public class BroadcastUDPVoiceService extends Service {

    public Boolean flag = true;

    /**
     * 录入的字节数组
     */
    private byte[] m_in_bytes;

    /**
     * 广播地址
     */
    public InetAddress serverAddress;


    public DatagramSocket recevieSocket;
    public final IBinder binder = new BroadcastUDPVoiceServiceBinder();

    private errorMsgListener listener;
    private int ports;
    private int CONTROL_PORT = 5288;


    private String danbo_Ip = "255.255.255.255";

    private void init() {


       /* m_in_bytes = new byte[1024];

        //初始化UDP的相应参数
        try {

            if (recevieSocket == null) {
                recevieSocket = new DatagramSocket(null);// <-- create an unbound socket first
                recevieSocket.setReuseAddress(true);//<-- can reuse port
                //socketAudio.bind(new InetSocketAddress(ports));//<-- now bind it
                recevieSocket.bind(new InetSocketAddress(ports));//<-- now bind it
                serverAddress = InetAddress.getByName(danbo_Ip);
            }


        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (SocketException e) {
            e.printStackTrace();
        }
*/

    }

    public void setListener(errorMsgListener listener) {
        this.listener = listener;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        init();
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);

    }


    @Override
    public void onDestroy() {

        super.onDestroy();
    }


    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }


    public class BroadcastUDPVoiceServiceBinder extends Binder {
        public BroadcastUDPVoiceService getService() {
            return BroadcastUDPVoiceService.this;
        }
    }

    public interface errorMsgListener {
        void getErrorMsg(String msg);
    }

    public boolean getIsRecord() {
        return flag;
    }

}
